package com.tywj.module.h5.provider

import android.util.Log
import androidx.fragment.app.FragmentActivity
import com.alibaba.android.arouter.facade.annotation.Route
import com.tencent.smtt.sdk.QbSdk
import com.tencent.smtt.sdk.QbSdk.PreInitCallback
import com.tywj.lib.core.common.util.AppUtil
import com.tywj.lib.core.common.util.LogUtil
import com.tywj.lib.core.common.view.BaseFragment
import com.tywj.lib.route.RouteNavigation
import com.tywj.module.h5.route.H5Route
import com.tywj.panda.customer.common.provider.IH5Service

/**
 * @desc H5组件服务
 * @author June Yang
 * @date 2020/4/17
 */
@Route(path = H5Route.H5_SERVICE)
class H5ServiceImpl : IH5Service {

    override fun initEnvironment() {

        //搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。
        val cb: PreInitCallback = object : PreInitCallback {
            override fun onViewInitFinished(isSuccess: Boolean) {
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                LogUtil.d(" onViewInitFinished is $isSuccess")
            }

            override fun onCoreInitFinished() {}
        }
        //x5内核初始化接口
        QbSdk.initX5Environment(AppUtil.context, null)
    }


    override fun toH5Activity(
        indexUrl: String, title: String, titleBgColor: Int, h5Data: String, fromPage: String,
        isShowCloseView: Boolean
    ): RouteNavigation {
        return H5Route.toH5Activity(indexUrl, title, titleBgColor, h5Data, fromPage, isShowCloseView)
    }

    override fun getH5Fragment(
        activity: FragmentActivity, indexUrl: String, titleBgColor: Int,
        h5Data: String, fromPage: String
    ): BaseFragment {
        return H5Route.getH5Fragment(activity, indexUrl, titleBgColor, h5Data, fromPage)
    }
}